package com.example.cxz2021606127.fragment;

import android.app.ProgressDialog;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.cxz2021606127.R;
import com.example.cxz2021606127.adapter.ViewPagerAdapter;
import com.example.cxz2021606127.newtypefragment.CaiJingFragment;
import com.example.cxz2021606127.newtypefragment.GuPiaoFragment;
import com.example.cxz2021606127.newtypefragment.GuoJiFragment;
import com.example.cxz2021606127.newtypefragment.GuoNeiFragment;
import com.example.cxz2021606127.newtypefragment.JianKangFragment;
import com.example.cxz2021606127.newtypefragment.JiaoYuFragment;
import com.example.cxz2021606127.newtypefragment.JunShiFragment;
import com.example.cxz2021606127.newtypefragment.KeJiFragment;
import com.example.cxz2021606127.newtypefragment.NBAFragment;
import com.example.cxz2021606127.newtypefragment.NvXingFragment;
import com.example.cxz2021606127.newtypefragment.ReBangFragment;
import com.example.cxz2021606127.newtypefragment.TiYuFragment;
import com.example.cxz2021606127.newtypefragment.TuiJianFragment;
import com.example.cxz2021606127.newtypefragment.XingZuoFragment;
import com.example.cxz2021606127.newtypefragment.YuErFragment;
import com.example.cxz2021606127.newtypefragment.YuLeFragment;
import com.example.cxz2021606127.newtypefragment.ZhengZhiFragment;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;


public class HomePageFragment extends Fragment {
    View view;
    private TabLayout tablayout;
    private ViewPager2 viewpager2;
    List<Fragment> fragmentList = new ArrayList<>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_home_page, container, false);
            tablayout = view.findViewById(R.id.tablayout);
            viewpager2 = view.findViewById(R.id.vp);
            tablayout.setTabMode(TabLayout.MODE_SCROLLABLE);  //设置tablayout可滑动
            fragmentList.add(new TuiJianFragment());
            fragmentList.add(new ReBangFragment());
            fragmentList.add(new GuoNeiFragment());
            fragmentList.add(new GuoJiFragment());
            fragmentList.add(new ZhengZhiFragment());
            fragmentList.add(new CaiJingFragment());
            fragmentList.add(new TiYuFragment());
            fragmentList.add(new YuLeFragment());
            fragmentList.add(new JunShiFragment());
            fragmentList.add(new JiaoYuFragment());
            fragmentList.add(new KeJiFragment());
            fragmentList.add(new NBAFragment());
            fragmentList.add(new GuPiaoFragment());
            fragmentList.add(new XingZuoFragment());
            fragmentList.add(new NvXingFragment());
            fragmentList.add(new JianKangFragment());
            fragmentList.add(new YuErFragment());

            ViewPagerAdapter adapter = new ViewPagerAdapter(getFragmentManager(), getLifecycle(), fragmentList);
            viewpager2.setAdapter(adapter);

            new TabLayoutMediator(tablayout, viewpager2, true, new TabLayoutMediator.TabConfigurationStrategy() {
                @Override
                public void onConfigureTab(@NonNull @NotNull TabLayout.Tab tab, int position) {
                    switch (position) {
                        case 0:
                            tab.setText("推荐");
                            break;
                        case 1:
                            tab.setText("热榜");
                            break;
                        case 2:
                            tab.setText("国内");
                            break;
                        case 3:
                            tab.setText("国际");
                            break;
                        case 4:
                            tab.setText("政治");
                            break;
                        case 5:
                            tab.setText("财经");
                            break;
                        case 6:
                            tab.setText("体育");
                            break;
                        case 7:
                            tab.setText("娱乐");
                            break;
                        case 8:
                            tab.setText("军事");
                            break;
                        case 9:
                            tab.setText("教育");
                            break;
                        case 10:
                            tab.setText("科技");
                            break;
                        case 11:
                            tab.setText("NBA");
                            break;
                        case 12:
                            tab.setText("股票");
                            break;
                        case 13:
                            tab.setText("星座");
                            break;
                        case 14:
                            tab.setText("女性");
                            break;
                        case 15:
                            tab.setText("健康");
                            break;
                        case 16:
                            tab.setText("育儿");
                            break;


                    }


                }
            }).attach();
        }
        return view;

    }

//    @Override
//    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
//        super.onViewCreated(view, savedInstanceState);
//        initView();
//        tablayout.setTabMode(TabLayout.MODE_SCROLLABLE);
//        fragmentList.add(new TuiJianFragment());
//        fragmentList.add(new ReBangFragment());
//        fragmentList.add(new GuoNeiFragment());
//        fragmentList.add(new GuoJiFragment());
//        fragmentList.add(new ZhengZhiFragment());
//        fragmentList.add(new CaiJingFragment());
//        fragmentList.add(new TiYuFragment());
//        fragmentList.add(new YuLeFragment());
//        fragmentList.add(new JunShiFragment());
//        fragmentList.add(new JiaoYuFragment());
//        fragmentList.add(new KeJiFragment());
//        fragmentList.add(new NBAFragment());
//        fragmentList.add(new GuPiaoFragment());
//        fragmentList.add(new XingZuoFragment());
//        fragmentList.add(new NvXingFragment());
//        fragmentList.add(new JianKangFragment());
//        fragmentList.add(new YuErFragment());
//
//
//        ViewPagerAdapter adapter = new ViewPagerAdapter(getFragmentManager(), getLifecycle(), fragmentList);
//        viewpager2.setAdapter(adapter);
//
//        new TabLayoutMediator(tablayout, viewpager2, true, new TabLayoutMediator.TabConfigurationStrategy() {
//            @Override
//            public void onConfigureTab(@NonNull @NotNull TabLayout.Tab tab, int position) {
//                switch (position) {
//                    case 0:
//                        tab.setText("推荐");
//                        break;
//                    case 1:
//                        tab.setText("热榜");
//                        break;
//                    case 2:
//                        tab.setText("国内");
//                        break;
//                    case 3:
//                        tab.setText("国际");
//                        break;
//                    case 4:
//                        tab.setText("政治");
//                        break;
//                    case 5:
//                        tab.setText("财经");
//                        break;
//                    case 6:
//                        tab.setText("体育");
//                        break;
//                    case 7:
//                        tab.setText("娱乐");
//                        break;
//                    case 8:
//                        tab.setText("军事");
//                        break;
//                    case 9:
//                        tab.setText("教育");
//                        break;
//                    case 10:
//                        tab.setText("科技");
//                        break;
//                    case 11:
//                        tab.setText("NBA");
//                        break;
//                    case 12:
//                        tab.setText("股票");
//                        break;
//                    case 13:
//                        tab.setText("星座");
//                        break;
//                    case 14:
//                        tab.setText("女性");
//                        break;
//                    case 15:
//                        tab.setText("健康");
//                        break;
//                    case 16:
//                        tab.setText("育儿");
//                        break;
//
//
//                }
//
//
//            }
//        }).attach();
//
//    }

    private void initView() {
        tablayout = view.findViewById(R.id.tablayout);
        viewpager2 = view.findViewById(R.id.vp);

    }
}